home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / uwserver.zip / uwserver.tar / h / uw_pcl.h < prev    next >
C/C++ Source or Header  |  1991-01-25  |  10KB  |  216 lines

  1. /*
  2.  *    uw protocol
  3.  *
  4.  * Copyright 1985,1986 by John D. Bruner.  All rights reserved.  Permission to
  5.  * copy this program is given provided that the copy is not sold and that
  6.  * this copyright notice is included.
  7.  */
  8.  
  9. #ifndef UW_PCL
  10. #define    UW_PCL
  11.  
  12. #include "uw_win.h"
  13.  
  14. /* UW may operate over connections which speak one of several protocols.
  15.  * Internally these protocols are assigned numbers starting at zero.
  16.  * Three such protocols are currently defined:
  17.  *
  18.  *    0: no special protocol
  19.  *    1: original UW (v1.6, v2.10) protocol
  20.  *    2: extended protocol (v3.x)
  21.  */
  22.  
  23. /*
  24.  * Protocol 0:
  25.  *
  26.  * The connection between the Macintosh and the host is simply a serial
  27.  * line.  Flow control may be enabled, but no special commands are
  28.  * recognized.  Only one active window is supported.  This "protocol"
  29.  * does not require the UW server; hence, there is no need to support it.
  30.  */
  31.  
  32. /*
  33.  * Protocol 1: (original UW protocol)
  34.  *
  35.  * Two types of information are exchanged through the 7-bit serial line:
  36.  * ordinary data and command bytes.  Command bytes are preceeded by
  37.  * an IAC byte.  IAC bytes and literal XON/XOFF characters (those which
  38.  * are not used for flow control) are sent by a P1_FN_CTLCH command.
  39.  * Characters with the eighth bit set (the "meta" bit) are prefixed with
  40.  * a P1_FN_META function.
  41.  *
  42.  * The next most-significant bit in the byte specifies the sender and
  43.  * recipient of the command.  If this bit is clear (0), the command byte
  44.  * was sent from the host computer to the Macintosh; if it is set (1)
  45.  * the command byte was sent from the Macintosh to the host computer.
  46.  * This prevents confusion in the event that the host computer
  47.  * (incorrectly) echos a command back to the Macintosh.
  48.  *
  49.  * The remaining six bits are partitioned into two fields.  The low-order
  50.  * three bits specify a window number from 1-7 (window 0 is reserved for
  51.  * other uses) or another type of command-dependent parameter.  The next
  52.  * three bits specify the operation to be performed by the recipient of
  53.  * the command byte.
  54.  *
  55.  * Note that the choice of command bytes prevents the ASCII XON (021) and
  56.  * XOFF (023) characters from being sent as commands.  P1_FN_ISELW commands
  57.  * are only sent by the Macintosh (and thus are tagged with the P1_DIR_MTOH
  58.  * bit).  Since XON and XOFF data characters are handled via P1_FN_CTLCH,
  59.  * this allows them to be used for flow control purposes.
  60.  */
  61. #define    P1_IAC        0001        /* interpret as command */
  62. #define    P1_DIR        0100        /* command direction: */
  63. #define    P1_DIR_HTOM    0000        /*    from host to Mac */
  64. #define    P1_DIR_MTOH    0100        /*    from Mac to host */
  65. #define    P1_FN        0070        /* function code: */
  66. #define    P1_FN_NEWW    0000        /*    new window */
  67. #define    P1_FN_KILLW    0010        /*    kill (delete) window */
  68. #define    P1_FN_ISELW    0020        /*    select window for input */
  69. #define    P1_FN_OSELW    0030        /*    select window for output */
  70. #define    P1_FN_META    0050        /*    add meta to next data char */
  71. #define    P1_FN_CTLCH    0060        /*    low 3 bits specify char */
  72. #define    P1_FN_MAINT    0070        /*    maintenance functions */
  73. #define    P1_WINDOW    0007        /* window number mask */
  74. #define    P1_CC        0007        /* control character specifier: */
  75. #define    P1_CC_IAC    1        /*    IAC */
  76. #define    P1_CC_XON    2        /*    XON */
  77. #define    P1_CC_XOFF    3        /*    XOFF */
  78. #define    P1_MF        0007        /* maintenance functions: */
  79. #define    P1_MF_ENTRY    0        /*    beginning execution */
  80. #define    P1_MF_ASKPCL    2        /*    request protocol negotiation */
  81. #define    P1_MF_CANPCL    3        /*    suggest protocol */
  82. #define    P1_MF_SETPCL    4        /*    set current protocol */
  83. #define    P1_MF_EXIT    7        /*    execution terminating */
  84. #define    P1_NWINDOW    7        /* maximum number of windows */
  85.  
  86. /*
  87.  * Protocol 2: (extended UW protocol)
  88.  *
  89.  * Protocol 2 is an extension of protocol 1.  The P2_FN_NEWW command and
  90.  * the new command P2_FN_WOPT communicate window options between the host
  91.  * and the Macintosh.  (See "uw_opt.h" for details.)
  92.  */
  93. #define    P2_IAC        P1_IAC        /* interpret as command */
  94. #define    P2_DIR        P1_DIR        /* command direction: */
  95. #define    P2_DIR_HTOM    P1_DIR_HTOM    /*    from host to Mac */
  96. #define    P2_DIR_MTOH    P1_DIR_MTOH    /*    from Mac to host */
  97. #define    P2_FN        P1_FN        /* function code: */
  98. #define    P2_FN_NEWW    P1_FN_NEWW    /*    new window */
  99. #define    P2_FN_KILLW    P1_FN_KILLW    /*    kill (delete) window */
  100. #define    P2_FN_ISELW    P1_FN_ISELW    /*    select window for input */
  101. #define    P2_FN_OSELW    P1_FN_OSELW    /*    select window for output */
  102. #define    P2_FN_WOPT    0040        /*    communicate window options */
  103. #define    P2_FN_META    P1_FN_META    /*    add meta to next data char */
  104. #define    P2_FN_CTLCH    P1_FN_CTLCH    /*    low 3 bits specify char */
  105. #define    P2_FN_MAINT    P1_FN_MAINT    /*    maintenance functions */
  106. #define    P2_WINDOW    P1_WINDOW    /* window number mask */
  107. #define    P2_CC        P1_CC        /* control character specifier: */
  108. #define    P2_CC_IAC    P1_CC_IAC    /*    IAC */
  109. #define    P2_CC_XON    P1_CC_XON    /*    XON */
  110. #define    P2_CC_XOFF    P1_CC_XOFF    /*    XOFF */
  111. #define    P2_MF        P1_MF        /* maintenance functions: */
  112. #define    P2_MF_ENTRY    P1_MF_ENTRY    /*    beginning execution */
  113. #define    P2_MF_ASKPCL    P1_MF_ASKPCL    /*    request protocol negotiation */
  114. #define    P2_MF_CANPCL    P1_MF_CANPCL    /*    suggest protocol */
  115. #define    P2_MF_SETPCL    P1_MF_SETPCL    /*    set current protocol */
  116. #define    P2_MF_EXIT    P1_MF_EXIT    /*    execution terminating */
  117. #define    P2_NWINDOW    P1_NWINDOW    /* maximum number of windows */
  118.  
  119. /*
  120.  * Protocol negotiation
  121.  *
  122.  * The server is not used for protocol 0.  For the other protocols, the
  123.  * Macintosh and the server negotiate to select the active protocol.  The
  124.  * basic idea is that the Macintosh will express its desire for a protocol
  125.  * and the server will attempt to satisfy that desire.  Until negotiations
  126.  * are complete, protocol 1 is used.
  127.  *
  128.  * Protocols are identified by single-character names which are formed by
  129.  * adding the ASCII code for a space (040) to the protocol number minus 1
  130.  * (i.e. protocol 1 is ' ', protocol 2 is '!').
  131.  *
  132.  * P1_FN_CANPCL and P1_FN_SETPCL are three-byte commands: P1_IAC,
  133.  * P1_FN_XXXPCL, protocol-name.
  134.  *
  135.  * Macintosh:
  136.  *    If UW v2.10 is used on the Macintosh or if a newer Macintosh program
  137.  *    wishes to use protocol 1, it will never initiate protocol negotiation.
  138.  *    Hence, all interaction will use protocol 1 by default.
  139.  *
  140.  *    If the Macintosh program is capable of supporting protocol 2 and the
  141.  *    user requests its use, the Mac will remember this fact but will
  142.  *    continue to use protocol 1.  The Mac program will assume that no
  143.  *    server is present until instructed otherwise by the user or until a
  144.  *    P1_FN_ENTRY command is received (e.g. when the server starts up).
  145.  *    At this time, the Mac program issues P1_FN_ASKPCL.  If the server
  146.  *    cannot support protocol 2 (i.e. it is an old server), then it will
  147.  *    ignore the P1_FN_ASKPCL.  The Macintosh will retry the P1_FN_ASKPCL
  148.  *    a couple of times (about five seconds apart) and, if there is no
  149.  *    response from the server, will abandon negotiations.  Protocol 1
  150.  *    will be used for the remainder of the session.
  151.  *
  152.  *    If the server recognizes the P1_FN_ASKPCL command it will respond
  153.  *    with the name of the most complex protocol it can support (currently
  154.  *    '!').  If this is acceptable to the Macintosh, it will instruct the
  155.  *    server to use this protocol.  If the Macintosh cannot support this
  156.  *    protocol it will respond with a P1_FN_CANPCL suggesting a less-complex
  157.  *    protocol.  If the server agrees to this it will answer establish the
  158.  *    protocol; otherwise, it will suggest an even weaker protocol.
  159.  *    Eventually someone will suggest protocol 1 (which is universal) and
  160.  *    the other side will issue a P1_FN_SETPCL command to establish its use.
  161.  *
  162.  * Host:
  163.  *    If the host receives a P1_FN_ASKPCL it will respond with the most
  164.  *    complex protocol it can support (using the P1_FN_CANPCL command).
  165.  *    Negotiations will proceed as described above until one side
  166.  *    establishes a new protocol with P1_FN_SETPCL.  At this time, the
  167.  *    host will switch to the new protocol.
  168.  *
  169.  *    If the host receives a P1_FN_ENTRY (P2_FN_ENTRY) command, it will
  170.  *    switch back to protocol 1.  Receipt of this command indicates that
  171.  *    the Macintosh program was restarted.  The Macintosh must initiate
  172.  *    protocol negotiations again.
  173.  */
  174.  
  175. /*
  176.  * Although many of the functions are identical (and the code is shared
  177.  * between them), each protocol is accessed through a (struct protocol)
  178.  * which specifies the functions for various operations.
  179.  *
  180.  * In theory, the main program knows nothing about the protocol in use.
  181.  * In practice, the externally-visible functions are accessed as macros
  182.  * for greater efficiency.
  183.  *
  184.  * The protocol layer is aware of the (struct window) data structures.
  185.  */
  186.  
  187. struct protocol {
  188.     char        p_name;        /* single-character protocol name */
  189.     nwin_t        p_maxwin;    /* maximum window number */
  190.     int        *p_ctlch;    /* control character map table */
  191.     unsigned    p_szctlch;    /* size (# of entries) in ctlch table */
  192.     void        (*p_entry)();    /* start up (ENTRY maintenance fn) */
  193.     void        (*p_exit)();    /* shut down (EXIT maintenance fn) */
  194.     void        (*p_renew)();    /* renew (re-init) */
  195.     struct window    *(*p_neww)();    /* create new window */
  196.     void        (*p_killw)();    /* kill window */
  197.     void        (*p_xmit)();    /* transmit to specified window */
  198.     void        (*p_recv)();    /* receive from Macintosh */
  199.     void        (*p_chkopt)();    /* check for pending option output */
  200.     void        (*p_sendopt)();    /* send option string to Macintosh */
  201.     void        (*p_askpcl)();    /* send an ASKPCL maintenance command */
  202.     void        (*p_canpcl)();    /* send a CANPCL maintenance command */
  203.     void        (*p_setpcl)();    /* send a SETPCL maintenance command */
  204. };
  205.  
  206. extern struct protocol *protocol;
  207.  
  208. #define    PCL_NEWW(mfd,class,wtype,wnum,wid,dfd,cfd) \
  209.     (*protocol->p_neww)(mfd,class,wtype,wnum,(long)wid,dfd,cfd)
  210. #define    PCL_KILLW(mfd,w)    (*protocol->p_killw)(mfd,w)
  211. #define    PCL_RECV(mfd,buf,len)    (*protocol->p_recv)(mfd,buf,len)
  212. #define    PCL_XMIT(mfd,w)    (*protocol->p_xmit)(mfd,w)
  213. #define    PCL_SENDOPT(mfd,fn,buf,len) \
  214.     (protocol->p_sendopt ? (*protocol->p_sendopt)(mfd,fn,buf,len) : 0)
  215. #endif
  216.